/*
 * Vektor.h
 *
 *  Created on: Feb 14, 2011
 *      Author: alki
 */

#ifndef VEKTOR_H_
#define VEKTOR_H_

#include <math.h>

/**
 * Klasse Vektor: Repräsentiert einen Vektor im IR^3
 */
class Vektor {
public:
	Vektor();
	Vektor(float x,float y,float z);
	virtual ~Vektor();

	void set(float x,float y,float z) { this->m_x = x; this->m_y = y; this->m_z = z; }
	void setX(float x) { this->m_x=x; }
	float getX() const { return this->m_x; }
	void setY(float y) { this->m_y=y; }
	float getY() const { return this->m_y; }
	void setZ(float z) { this->m_z=z; }
	float getZ() const { return this->m_z; }
	void setAngle(double alpha,double beta);

	/**
	 * rotiert den Vektor um die x-y-z-Achsen
	 */
	void Rotate(float x,float y,float z,bool rueck=false);
	/**
	 * verschiebt den Vektor
	 */
	void Translate(const Vektor v) { Translate(v.m_x,v.m_y,v.m_z); }
	void Translate(float x,float y,float z) { this->m_x+=x; this->m_y+=y; this->m_z+=z; }

	/**
	 * Skalar- und Kreuzprodukt
	 */
	float ScalarProduct(const Vektor &v) const;
	Vektor CrossProduct(const Vektor &v) const;

	/**
	 * berechnet die Länge, die Länge im Quadrat bzw. normalisiert den Vektor
	 */
	float Length() const { return sqrt(this->ScalarProduct(*this)); }
	float LengthQuad() const { return this->ScalarProduct(*this); }
	void Normalize() { float l=this->Length(); this->m_x/=l; this->m_y/=l; this->m_z/=l; }

	/**
	 * Vektoraddition/-subtraktion
	 */
	Vektor operator-(const Vektor &v) const;
	Vektor operator+(const Vektor &v) const;
	/**
	 * Vektormultiplikation/-division mit Skalar
	 */
	Vektor operator*(float n) const;
	Vektor operator/(float n) const { return *this*(1/n); }

	/**
	 * Nicht-Standard!
	 * überprüft ob eine Komponente kleiner ist!
	 */
	bool operator<(const Vektor &v) const { return ((this->m_x<v.m_x)||(this->m_y<v.m_y)||(this->m_z<v.m_z)); }
	bool operator>(const Vektor &v) const { return v<*this; }

	void out() const;

private:
	float m_x;
	float m_y;
	float m_z;
};

#endif /* VEKTOR_H_ */
